#include "topmenubtns.h"
#include "ui_topmenubtns.h"

#include <QRadioButton>

TopMenuBtns::TopMenuBtns(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TopMenuBtns)
{
    ui->setupUi(this);
}

TopMenuBtns::~TopMenuBtns()
{
    delete ui;
}

void TopMenuBtns::setMenu(QStringList str)
{
    clear();
    for(auto s:str){
        auto btn = new QRadioButton(s,this);
        connect(btn,&QRadioButton::clicked,[=](){
            emit clicked(s);
        });
        ui->layout->addWidget(btn);
    }
}

void TopMenuBtns::setMenuAndData(QList<QPair<QString, QString> > data)
{
    clear();
    for(auto s:data){
        auto btn = new QRadioButton(s.first,this);
        connect(btn,&QRadioButton::clicked,[=](){
            emit clicked(s.second);
        });
        ui->layout->addWidget(btn);
    }
}

void TopMenuBtns::clear()
{
    for(auto &&item : ui->layout->children()){
        ui->layout->removeWidget(qobject_cast<QWidget*>(item));
    }

}
